home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume18 / changebar < prev    next >
Encoding:
Internet Message Format  |  1989-03-12  |  12.5 KB

  1. Subject:  v18i018:  Generate changebars in ?roff docs using patch
  2. Newsgroups: comp.sources.unix,comp.text
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: rap@ardent.com (Rob Peck)
  7. Posting-number: Volume 18, Issue 18
  8. Archive-name: changebar
  9.  
  10. [  This is the best of the several of these that I've seen.  -r$ ]
  11.  
  12. a program for automatically adding change-bars to nroff/troff
  13. documents.  See the CONTENTS file and the accompanying man-pages
  14. for more information.  NOTE: REQUIRES Larry Wall's 'patch' program.
  15.  
  16. Rob Peck
  17. Ardent Computer
  18.                              
  19. #! /bin/sh
  20. # This is a shell archive.  Remove anything before this line, then unpack
  21. # it by saving it into a file and typing "sh file".  To overwrite existing
  22. # files, type "sh file -c".  You can also feed this as standard input via
  23. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  24. # will see the following message at the end:
  25. #        "End of shell archive."
  26. # Contents:  CONTENTS README changebar changebar.1 chbar.lex
  27. #   delete.note
  28. # Wrapped by rsalz@papaya.bbn.com on Mon Mar 13 18:20:02 1989
  29. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  30. if test -f 'CONTENTS' -a "${1}" != "-c" ; then 
  31.   echo shar: Will not clobber existing file \"'CONTENTS'\"
  32. else
  33. echo shar: Extracting \"'CONTENTS'\" \(1565 characters\)
  34. sed "s/^X//" >'CONTENTS' <<'END_OF_FILE'
  35. XThe shell script 'changebar' uses Larry Wall's 'patch' program
  36. Xto automatically install "change-bars" into an nroff/troff document.
  37. XThe output of a context diff is modified by a lex-generated c program
  38. Xto incorporate the changebars as though they are part of the differences
  39. Xbetween the two files in the first place.  Then when patch runs, it
  40. Xadds the change bars to the text.  After the patch processing, one more
  41. Xpost-processing operation is performed to add line feeds to the final
  42. Xtext, replacing ^G characters that were installed so that patch would
  43. Xbe able to run entirely unmodified.
  44. X
  45. XMy thanks to Larry Wall for creating 'patch' in the first place.
  46. XThis program was prompted by a request by some of my engineers who
  47. Xwanted to be able to "use SCCS to edit to my heart's content, then
  48. Xwhen finally ready to reissue the document, have the change bars
  49. Xinstalled automatically."  It seems to work, so here it is.  If
  50. Xanyone makes any changes, I would like to hear about them; hope it
  51. Xhelps a few folks.
  52. X
  53. XReleased to the public domain, unsupported, do with it as you wish.
  54. X
  55. XThe files contained here are:
  56. X    changebar - a shell script
  57. X    chbar.lex - the lex script that compiles into a
  58. X            context-diff examiner/modifier as a
  59. X            preprocessing step before patch is used.
  60. X    chbar.1   - the man page that explains chbar.lex
  61. X    changebar.1 - the man page for the changebar script.
  62. X              The FILES item will have to be modified
  63. X              depending on where on your own system
  64. X              you install things.
  65. X
  66. XRob Peck    Ardent Computer, 880 W. Maude Ave, Sunnyvale, Ca. 94086
  67. X
  68. END_OF_FILE
  69. if test 1565 -ne `wc -c <'CONTENTS'`; then
  70.     echo shar: \"'CONTENTS'\" unpacked with wrong size!
  71. fi
  72. # end of 'CONTENTS'
  73. fi
  74. if test -f 'README' -a "${1}" != "-c" ; then 
  75.   echo shar: Will not clobber existing file \"'README'\"
  76. else
  77. echo shar: Extracting \"'README'\" \(631 characters\)
  78. sed "s/^X//" >'README' <<'END_OF_FILE'
  79. XChangebar only works with files in the current directory.  For example,
  80. X
  81. X    changebar foo1 foo2
  82. X
  83. Xworks fine, but:
  84. X
  85. X    changebar /tmp/foo1 /otherpath/foo2
  86. X
  87. Xdoes not work.  I believe that patch is having a problem with paths.
  88. X
  89. XSo this is just a quick warning to users that this limitation exists.
  90. XI do not plan to fix it, however a user who wanted to fix the situation
  91. Xcould, I suppose, copy each file to a known name in /tmp, for example,
  92. Xthen pushd to /tmp, do the changebar work there, then delete the temp
  93. Xfiles, copy the .chbar result to the original directory and finally
  94. Xget rid of any other temp files that we created.
  95. X
  96. XRob Peck
  97. END_OF_FILE
  98. if test 631 -ne `wc -c <'README'`; then
  99.     echo shar: \"'README'\" unpacked with wrong size!
  100. fi
  101. # end of 'README'
  102. fi
  103. if test -f 'changebar' -a "${1}" != "-c" ; then 
  104.   echo shar: Will not clobber existing file \"'changebar'\"
  105. else
  106. echo shar: Extracting \"'changebar'\" \(1422 characters\)
  107. sed "s/^X//" >'changebar' <<'END_OF_FILE'
  108. X#!/bin/sh
  109. X#
  110. X#  Script to automatically add changebars to troff docs.
  111. X#
  112. Xif [ $# -lt 1 ]; then
  113. X#
  114. X#  If user does not enter parameters, show usage info.
  115. X#
  116. X    echo
  117. X    echo "    changebar --> Usage:   changebar OLDFILE NEWFILE"
  118. X    echo
  119. X    echo "    Produces NEWFILE.chbar that is NEWFILE with changebars,"
  120. X    echo "    leaves original files intact."
  121. X    echo
  122. Xelse
  123. X#  Run a context diff on the two files
  124. X#
  125. X    diff -c $2 $1 > $1.diff
  126. X#
  127. X#  Install change bars in the context diff,
  128. X#  for ADDITIONS and MODIFICATIONS only.
  129. X#  DELETIONS not marked -- reverse the
  130. X#  sequence of the file names and run it
  131. X#  again to get an original file with
  132. X#  deletions and modifications marked.
  133. X#
  134. X    chbar < $1.diff > $1.patch
  135. X#
  136. X#  Run the patch program to install the
  137. X#  now-modified context diffs.
  138. X#
  139. X    patch -R < $1.patch
  140. X#
  141. X#  Remove the intermediate files;
  142. X#  assumes that all of the patches worked.
  143. X#
  144. X    rm $1.diff $1.patch
  145. X#
  146. X#  Translate ^G to \n, installed for
  147. X#  convenience to make patch work unmodified.
  148. X#  Name the filtered version as $2.chbar.
  149. X#
  150. X    tr '\007' '\012' < $1 > $2.chbar
  151. X#
  152. X#  Make the patched (intermediate) file removable
  153. X#
  154. X    chmod 666 $1
  155. X#
  156. X#  Patch renamed original file;
  157. X#  restore the original name
  158. X#
  159. X    mv $1.orig $1
  160. X#
  161. X#  Now tell the user what we did.
  162. X#
  163. X    echo 
  164. X    echo "All of the hunks should have succeeded"
  165. X    echo
  166. X    echo "There is now a new file named $2.chbar that is exactly"
  167. X    echo "like your file named $2, but it has changebars installed."
  168. X    echo
  169. Xfi
  170. END_OF_FILE
  171. if test 1422 -ne `wc -c <'changebar'`; then
  172.     echo shar: \"'changebar'\" unpacked with wrong size!
  173. fi
  174. # end of 'changebar'
  175. fi
  176. if test -f 'changebar.1' -a "${1}" != "-c" ; then 
  177.   echo shar: Will not clobber existing file \"'changebar.1'\"
  178. else
  179. echo shar: Extracting \"'changebar.1'\" \(1356 characters\)
  180. sed "s/^X//" >'changebar.1' <<'END_OF_FILE'
  181. X.TH CHBAR 1L "October 7, 1988" "" "User Contributed Software"
  182. X.SH NAME
  183. Xchbar \- modify a context diff to add change bars 
  184. X.br
  185. X.nf
  186. X        before running patch
  187. X.fi
  188. X.SH SYNOPSIS
  189. X.B changebar OLDFILE NEWFILE
  190. X.SH FUNCTION
  191. XInstalls ".mc |^G" as part of the first line of a changed-line
  192. Xregion and is part of the first line of a region of added-lines
  193. Xas indicated by a context diff 
  194. X.br
  195. X.sp
  196. X.nf
  197. X    (diff -c oldfile newfile).
  198. X.fi
  199. X.sp
  200. X.PP
  201. XAlso installs "^G.mc" as part of the last line of a changed-line
  202. Xregion, and as part of the last line of an added-line region.
  203. XThis fools the patch program into believing that these characters
  204. Xare part of the patch to be installed to create the new file.
  205. XFollowing running patch, a filter must be run to change the
  206. XControl-G characters into line feeds;  results in placing
  207. Xthe ".mc |" on a separate line ahead of the changed region
  208. Xand the ".mc" on a separate line just following the end of
  209. Xthe changed region, thus causing the region to be marked.
  210. X.SH LIMITATIONS
  211. XSee LIMITATIONS in the man-page that describes ``changebar''.
  212. X.SH AUTHOR
  213. XRob Peck \- Ardent Computer
  214. X.SH FILES
  215. X/usr/local/lib/chbar.lex
  216. X.br
  217. X/usr/local/bin/chbar
  218. X.br
  219. X/usr/local/lib/PATCH.src (source directory)
  220. X.br
  221. X/usr/local/bin/patch (by Larry Wall) \- version 2.0
  222. X.br
  223. X/usr/local/bin/changebar (a shell script)
  224. X.SH BUGS
  225. XNone known at this time.
  226. X.SH DATE
  227. X10/7/88
  228. END_OF_FILE
  229. if test 1356 -ne `wc -c <'changebar.1'`; then
  230.     echo shar: \"'changebar.1'\" unpacked with wrong size!
  231. fi
  232. # end of 'changebar.1'
  233. fi
  234. if test -f 'chbar.lex' -a "${1}" != "-c" ; then 
  235.   echo shar: Will not clobber existing file \"'chbar.lex'\"
  236. else
  237. echo shar: Extracting \"'chbar.lex'\" \(3615 characters\)
  238. sed "s/^X//" >'chbar.lex' <<'END_OF_FILE'
  239. X/* Compile this program using lex and cc, name the object file 'chbar'
  240. X * and install it somewhere that the system can get to it using the
  241. X * 'changebar' shell script.
  242. X */
  243. X%{
  244. Xint stat=0;
  245. Xint bangstat=0;
  246. Xchar txtbuf[256]=0;
  247. X%}
  248. X%%
  249. X^[^-\*\n\!].*$     {
  250. X                /* If already counting lines that have either a '- '
  251. X                 * or a '! ' or a '*...' in the first columns, and encounter
  252. X                 * a line that does NOT have that, put the closing
  253. X                 * ^G.mc at the tail of the previous line and disable
  254. X                 * the insertion of the .mc till the first line with
  255. X                 * either of the two markers happens again.
  256. X                 */
  257. X                    if(stat == 1) {
  258. X                        printf("%s\007.mc\n",txtbuf);
  259. X                        stat = 0;
  260. X                    }
  261. X                    puts(yytext);
  262. X                }
  263. X
  264. X^---\ .*$       {   puts(yytext);  /* If in a '---' block in a context diff,
  265. X                                * then disable entry of .mc's in text lines.
  266. X                                */
  267. X                    bangstat = 0;
  268. X                }
  269. X
  270. X^\*\*\*\ .*$    {   puts(yytext);  /* If in a '***' block in a context diff,
  271. X                                * then enable entry of .mc's in text lines.
  272. X                                */
  273. X                    bangstat = 1;
  274. X                }
  275. X
  276. X^\*\*\*.*$    {   puts(yytext);
  277. X        }
  278. X
  279. X^\-\ .*$        {
  280. X                    /* If find a line that begins "- <anything>", and it
  281. X                     * is the first line of its kind, then mark it.
  282. X                     */
  283. X                if(stat == 0) {
  284. X                    sprintf(txtbuf,"- .mc \\s+2\\(br\\s-2\007%s",&yytext[2]);
  285. X                    stat = 1;
  286. X                    }
  287. X                else {
  288. X                    puts(txtbuf);
  289. X                    sprintf(txtbuf,"%s",yytext);
  290. X                    }
  291. X                }
  292. X
  293. X
  294. X
  295. X
  296. X
  297. X
  298. X
  299. X
  300. X^\!\ .*$        {
  301. X                    /* If find a line that begins "! <anything>", and it
  302. X                     * is the first line of its kind, then mark it.
  303. X                     */
  304. X                  if(bangstat==1) 
  305. X                  {
  306. X                        if(stat == 0) {
  307. X                          sprintf(txtbuf,"! .mc \\s+2\\(br\\s-2\007%s",
  308. X                                      &yytext[2]);
  309. X                          stat = 1;
  310. X                        }
  311. X                        else {
  312. X                          puts(txtbuf);
  313. X                          sprintf(txtbuf,"%s",yytext);
  314. X                          }
  315. X                  }
  316. X                  else {
  317. X                    puts(yytext);
  318. X                  }
  319. X                }
  320. X\n          {
  321. X                   ;
  322. X           /* If there is nothing but a newline, do nothing, because
  323. X                    * we are inserting our own newlines as needed.
  324. X                    */
  325. X        }
  326. X%%
  327. Xyywrap()
  328. X{
  329. X    if (stat == 1)
  330. X        printf("%s\007.mc\n",txtbuf);
  331. X
  332. X    return (1);
  333. X}
  334. X/*
  335. X    This LEX file adds change bars to the output of a 'diff -c'
  336. X    to indicate to the reader where sections have been added
  337. X    (no handling so far for lines that have been deleted).
  338. X
  339. X    This allows the user to edit under SCCS to your heart's content,
  340. X    then SCCS-extract the old version and the new version...
  341. X    then:
  342. X
  343. X    a. diff -c oldfile newfile > filediffs
  344. X    b. addchgbars < filediffs > filemods
  345. X    c. patch < filemods
  346. X    
  347. X    # oldfile is renamed to oldfile.orig
  348. X    # oldfile becomes newfile, but with change bars installed
  349. X
  350. X    d. tr '\007' '\012' oldfile > file.to.print
  351. X
  352. X    # change bars have ^G installed, has to be changed into a ^J;
  353. X    # makes patch program work unmodified.
  354. X
  355. X*/
  356. END_OF_FILE
  357. if test 3615 -ne `wc -c <'chbar.lex'`; then
  358.     echo shar: \"'chbar.lex'\" unpacked with wrong size!
  359. fi
  360. # end of 'chbar.lex'
  361. fi
  362. if test -f 'delete.note' -a "${1}" != "-c" ; then 
  363.   echo shar: Will not clobber existing file \"'delete.note'\"
  364. else
  365. echo shar: Extracting \"'delete.note'\" \(634 characters\)
  366. sed "s/^X//" >'delete.note' <<'END_OF_FILE'
  367. XMARKING DELETIONS TO THE TEXT
  368. X
  369. XThere is no EASY way I can find to appropriately mark DELETIONS to
  370. Xa file with change bars.  Either do deletions manually, or run this
  371. Xprogram in reverse:
  372. X
  373. X    changebar NEW OLD
  374. X
  375. XThis will create a file named OLD.chbar, which will be the exact
  376. Xequivalent of the OLD file, but with change bars marking the deleted
  377. Xtext.  You could therefore print an NEW.chbar (equal to the NEW file
  378. Xwith change bars indicating added text) and OLD.chbar (equal to the
  379. XOLD file with deleted text highlighted) for your users and they'd
  380. Xhave a complete picture showing what you did to the files between
  381. Xissues of the document.
  382. END_OF_FILE
  383. if test 634 -ne `wc -c <'delete.note'`; then
  384.     echo shar: \"'delete.note'\" unpacked with wrong size!
  385. fi
  386. # end of 'delete.note'
  387. fi
  388. echo shar: End of shell archive.
  389. exit 0
  390.